package com.example.appxi;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;

public class PlaceActivity extends ParentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_place);
        top=this;
        ViewPager pager = (ViewPager)findViewById(R.id.placepager);
        pager.setAdapter(new myPagerAdapter(this));
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
class myPagerAdapter extends PagerAdapter{

    private LayoutInflater mInflater;
    
    public myPagerAdapter(Context context) {
        super();
        mInflater = LayoutInflater.from(context);
    }
    
    // PagerAdapter에서 관리할 View 개수를 반환합니다.
    public int getCount() {
        return 3;
    }
    
    // ViewPager에서 사용할 View를 생성하고 등록해줍니다.
    public Object instantiateItem(View pager, int position){
        View v = null;
        
        switch(position){
        case 0:
            v = mInflater.inflate(R.layout.frag_place_left, null);
            break;
        case 1:
            v = mInflater.inflate(R.layout.frag_place, null);
            break;
        case 2:
            v = mInflater.inflate(R.layout.frag_place_right, null);
            break;
        }
        
        ((ViewPager)pager).addView(v, null);
        
        return v;
    }

    // View를 삭제합니다.
    public void destroyItem(View pager, int position, Object view) {
        ((ViewPager)pager).removeView((View)view);
    }
    
    // instantiateItem에서 생성한 객체를 이용할 것인지 여부를 반환합니다.
    @Override
    public boolean isViewFromObject(View v, Object obj) {
        return v == obj;
    }

}
